#include "common.hpp"

int main()
{
    key_t shm_key = getKey();

    printf("shm_key: 0X%x\n", shm_key);

    int shmid = getShm(shm_key);
    printf("shmid: %d\n", shmid);

    sleep(3);

    char *start = (char*)attchShm(shmid);
    printf("arrchShm success , address start : %p\n", start);
    sleep(5);

    const char *massage = "我是另一个进程，正在通信";

    pid_t pid = getpid();
    size_t cnt = 0;
    while (cnt <= 5)
    {
        sleep(1);
        snprintf(start, MAX_SIZE, "%s[pid:%d][消息编号:%d]", massage, pid, cnt);
        ++cnt;
    }
    deattchShm(start);

    return 0;
}